package cn.com.sparkle.paxos.event;

public abstract class MasterChangePosEvent implements Event {
	public final static int GET_POS_MASTER = 1;
	public final static int LOST_POS_MASTER = 2;
	public final static int MASTER_CHANGE = 3;

	@Override
	public void event(Object... args) {
		int type = (Integer) args[0];
		switch (type) {
		case GET_POS_MASTER:
			getMasterPos();
			break;
		case LOST_POS_MASTER:
			lostPos();
			break;
		case MASTER_CHANGE:
			masterChange((String) args[1]);
		}
	}

	public final static void doGetMasterPosEvent(EventsManager eventsManager) {
		eventsManager.doEvent(MasterChangePosEvent.class, GET_POS_MASTER);
	}

	public final static void doLostPosEvent(EventsManager eventsManager) {
		eventsManager.doEvent(MasterChangePosEvent.class, LOST_POS_MASTER);
	}

	public final static void doMasterChangeEvent(EventsManager eventsManager,
			String address) {
		eventsManager.doEvent(MasterChangePosEvent.class, MASTER_CHANGE,
				address);
	}

	public abstract void getMasterPos();

	public abstract void lostPos();

	public abstract void masterChange(String address);
}
